Option Explicit

'  Author:     $Author: PauThompson.CACI.com@gmail.com $
'  Creator:    $Creator$
'  Originator: $Originator:$
'  Date:       $Date: 2014-11-29 16:36:53 +0000 (Sat, 29 Nov 2014) $
'  DateTime:   $DateTime$
'  File:       $File$
'  Script:     $Script$
'  Requires:   $Requires$
'  Provides:   $Provides$
'  Change:     $Change$
'  Revision:   $Revision: 10 $
'  URL:        $URL: http://legato-vibrato.googlecode.com/svn/office_doc_file_smart_rename/trunk/OfficeDocFileSmartRename.vbs $
'  Id:         $Id: OfficeDocFileSmartRename.vbs 10 2014-11-29 16:36:53Z PauThompson.CACI.com@gmail.com $
'  Header:     $Header: http://legato-vibrato.googlecode.com/svn/office_doc_file_smart_rename/trunk/OfficeDocFileSmartRename.vbs 10 2014-11-29 16:36:53Z PauThompson.CACI.com@gmail.com $

dim regex_DateSpec , regex_RevSpec
set regex_DateSpec = New RegExp
set regex_RevSpec = New RegExp
regex_RevSpec.IgnoreCase = True
regex_DateSpec.Pattern = "\.\d{8,12}\."
regex_RevSpec.Pattern = "\.r[ev]*\d+\."


Dim obj_UnNamedArgs , fso , i , str_FName , obj_Property , obj_OfficeDoc , str_PropVal
Dim str_AppName , str_Rev , str_LastSaveTime , dat_LastSave , str_YYYYMMDDhhmm
Dim str_FileName , obj_Folder , str_FolderName

str_YYYYMMDDhhmm = "111122334455"

Set obj_UnNamedArgs = WScript.Arguments.UnNamed
Set fso = CreateObject("Scripting.FileSystemObject")

For i=0 to obj_UnNamedArgs.length-1
   wscript.echo "arg[" & i & "]==" & obj_UnNamedArgs(i)
   str_FName = fso.GetAbsolutePathName(obj_UnNamedArgs(i))
   wscript.echo "str_FName=" & str_FName
   str_FolderName = fso.GetParentFolderName(str_FName)
   wscript.echo "parentFolder=" & str_FolderName
   
   wscript.echo "GetFileName()=" & fso.GetFileName(str_FName)
   wscript.echo "GetBaseName()=" & fso.GetBaseName(str_FName)
   wscript.echo "GetExtensionName()=" & fso.GetExtensionName(str_FName)
dim x
   If regex_DateSpec.Test( fso.GetFileName(str_FName) ) Then
      x=regex_DateSpec.replace(str_FName,str_YYYYMMDDhhmm)
      wscript.echo "return val=" & x & "   modified str=" & str_FName
   Else
   End If

   If regex_RevSpec.Test( fso.GetFileName(str_FName) ) Then
   Else
   End If
   
Next



Set obj_OfficeDoc = GetObject("C:\Users\pthompson\Documents\Serena\Time\timesheet.20121104-20121110.xlsx")
Set obj_OfficeDoc = GetObject("C:\Users\pthompson\Documents\Serena\Consulting Services Work\_Western\IXIA\Phase 2\Upgrade Docs\TT to SBM Upgrade Steps for Ixia.201211091610.doc")


str_AppName = GetPropValue(obj_OfficeDoc,"Application name")
str_Rev = GetPropValue(obj_OfficeDoc,"Revision number")
str_LastSaveTime = GetPropValue(obj_OfficeDoc,"Last save time")
dat_LastSave = CDate(str_LastSaveTime)
' Get Document Last Save Time formatted as YYYYMMDDhhmm
str_YYYYMMDDhhmm = CStr(Year(dat_LastSave)) & TwoDigit(Month(dat_LastSave)) & TwoDigit(Day(dat_LastSave)) & TwoDigit(Hour(dat_LastSave)) & TwoDigit(Minute(dat_LastSave))
If Len(str_Rev) Then str_Rev = ".r" & CStr(str_Rev)

wscript.echo "str_YYYYMMDDhhmm=" & str_YYYYMMDDhhmm


Select Case LCase(str_AppName)
   Case "microsoft excel"
   Case "microsoft office word"
End Select




Function PropertyHasValue(obj)
   Dim s
   PropertyHasValue = False
   On Error Resume Next
   s = Typename(obj.Value)
   If Err.Number = 0 Then PropertyHasValue = True
   On Error Goto 0
End Function


Function GetPropValue(obj,strProp)
   Dim obj_Prop
   Set obj_Prop = obj.BuiltInDocumentProperties(strProp)
   If PropertyHasValue(obj_Prop) Then GetPropValue = obj_Prop.Value Else GetPropValue = Empty
End Function

Function TwoDigit(vnt)
   dim s
   s = CStr(vnt)
   While Len(s) < 2
      s = "0" & s
   Wend
   wscript.echo "param = " & vnt & "  isa " & typename(vnt) & " == '" & s & "'"
   TwoDigit = s
End Function

Function BaseNameLessDateTimeRev(str)
   Dim obj_Regex
   Set obj_Regex = new RegExp
   
End Function
